package testGuava.example.testSpring;

import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.util.FileCopyUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName : org.example.testSpring.FileCopyUtils
 * @Description : 类描述
 * Created by cyd on 2021-09-15 16:48:36
 */
public class FileCopyUtilsTest {

    /**
     * 将输入流的内容，拷贝到输出流中
     * 会自动关闭流
     */
    @Test
    public void test() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("files/123.txt");
        EncodedResource encodedResource = new EncodedResource(classPathResource, StandardCharsets.UTF_8);

        String targetPath = "D:\\WorkSpace\\test-guava\\src\\main\\resources\\files\\1234.txt";
        FileCopyUtils.copy(encodedResource.getInputStream(), new FileOutputStream(targetPath));
    }
}
